# Author    :Dun_Hz
# Time      :2025-04-07 16:54
import collections

n=int(input())
a=[]
for i in range(n):
    row=list(map(int, input().split()))
    a.append(row)
e=list(map(int, input().split()))
e.sort()

def dfs(x):
    q=collections.deque()
    vis=[0]*n

    for i in range(len(e)):
        if i!=x:
            q.append((10, e[i]))
    while q:
        w, u =q.popleft()
        if vis[u]==1:
            continue
        vis[u]=1
        for j in range(n):
            if w>=a[u][j]>0 and vis[j]==0:
                q.append((a[u][j], j))
    res = sum(vis)
    return res

mx=float('inf')
id=-1
for i in range(len(e)):
    now=dfs(i)
    if now<mx:
        mx=now
        id=i

print(e[id])
